package com.example.xm.controller;

import com.example.xm.entity.Geshou;
import com.example.xm.service.IGeshouService;
import com.example.xm.web.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/geshou")
public class GeshouController {
    @Autowired
    IGeshouService geshouService;
    @GetMapping("/list")
    public Result list(Geshou geshou) {
        PageInfo<Geshou> geshous = geshouService.selectList(geshou);
        return Result.success(geshous);
    }
    @GetMapping("/getData")
    public Result getData(Integer id) {
        Geshou geshous = geshouService.getData(id);
        return Result.success(geshous);
    }
    @PostMapping("/add")
    public Result add(@RequestBody  Geshou geshou) {
        return Result.success(geshouService.add(geshou));
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody Geshou geshou) {
        return Result.success(geshouService.edit(geshou));
    }
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        String[] split = ids.split(",");
        int[] intArray = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            intArray[i] = Integer.parseInt(split[i]);
        }
        geshouService.delete(intArray);
        return Result.success();
    }
}
